import React from 'react';
import { connect } from 'umi';

import { Form, message, Input, Row, Col, Space, Button, Select } from 'antd';
const OPTIONS = ['可提升', '达标', '优秀'];
const OPTIONEPiS = [
  '您的宝宝该能力暂时落后，请注意加强训练哦～',
  '您的宝宝指标正常，可多加练习更上一层楼哦～',
  '您的宝宝非常优秀，请继续保持哟～',
];
const currControl = 'Edu_Evaluation';
class Evaluation extends React.Component<any, any> {
  constructor(props: any) {
    super(props);
    this.state = {
      dataSource: [],
      visible: false,
    };
  }
  formRef: any = React.createRef();
  onFinish = async (values: any) => {
    console.log(values);

    const { dispatch, params } = this.props;
    var act = 'Abp/create';
    const { creationTime, grade, range, epilogue } = values;
    console.log(values);

    dispatch({
      type: act,
      payload: {
        creationTime,
        bankNum: params.bankNum,
        grade,
        range,
        epilogue,
      },
      control: currControl,
    }).then(() => {
      var resp = this.props.response;
      console.log(resp);

      if (resp.success) {
        message.success('保存成功！');
        this.setState({ visible: false });
        // 刷新列表
      } else {
        message.error('保存错误，请联系管理员');
      }
    });
  };
  render() {
    const { params } = this.props;
    console.log(params);
    return (
      <>
        <Form ref={this.formRef} layout="vertical" onFinish={this.onFinish}>
          <Row gutter={4}>
            <Col span={8}>
              <Form.Item
                label="分数"
                name="range"
                rules={[{ required: true, message: '请输入分数范围' }]}
              >
                <Input />
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item
                label="等级"
                name="grade"
                rules={[{ required: true, message: '请输入等级' }]}
              >
                <Select allowClear>
                  {OPTIONS.map((item) => (
                    <Select.Option key={item} value={item}>
                      {item}
                    </Select.Option>
                  ))}
                </Select>
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item label="题库编号" name="bankNum">
                <Input disabled={true} defaultValue={params.bankNum} />
              </Form.Item>
            </Col>
          </Row>
          <Form.Item
            label="结语"
            name="epilogue"
            rules={[{ required: true, message: '请输入结语' }]}
          >
            <Select allowClear>
              {OPTIONEPiS.map((item) => (
                <Select.Option key={item} value={item}>
                  {item}
                </Select.Option>
              ))}
            </Select>
          </Form.Item>
          <Row>
            <Col offset={10} span={10}>
              <Form.Item>
                <Space>
                  <Button type="primary" htmlType="submit">
                    保存
                  </Button>
                </Space>
              </Form.Item>
            </Col>
          </Row>
        </Form>
      </>
    );
  }
}
export default connect(({ Abp }: API.IConnectState) => ({
  response: Abp.response,
  currentUser: Abp.currentUser,
}))(Evaluation);
